package com.hstc.controller;

import com.alibaba.cloud.ai.dashscope.agent.DashScopeAgent;
import com.alibaba.cloud.ai.dashscope.agent.DashScopeAgentOptions;
import com.alibaba.cloud.ai.dashscope.api.DashScopeAgentApi;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AgentController {
    @Value("${spring.ai.dashscope.agent.options.app-id}")
    private String appId;
    private DashScopeAgent dashScopeAgent;
    public AgentController(DashScopeAgentApi dashScopeAgentApi){
        this.dashScopeAgent = new DashScopeAgent(dashScopeAgentApi);
    }

    @GetMapping("/agent")
    public String agent(@RequestParam(name = "msg",defaultValue = "口水鸡怎么做") String msg){
        DashScopeAgentOptions options =  DashScopeAgentOptions.builder()
                .withAppId(appId)
                .build();
        Prompt prompt = new Prompt(msg, options);
        return dashScopeAgent.call(prompt)
                .getResult()
                .getOutput()
                .getText();
    }
}
